#ifndef _GS_DB_H_
#define _GS_DB_H_
/*******************************************************************************
 **  Name: db.h                                                               **
 **  Description:                                                             **
 **                                                                           **
 **  Open Source Initiative (OSI) Approved License                            **
 **                                                                           **
 **  Copyright (c) 2009-2010 Barry "Gian" James  <bjames@munixos.net>         **
 **  All rights reserved.                                                     **
 **                                                                           **
 **  The contents of this file are subject to the terms of the CDDL:          **
 **  Common Development and Distribution License (the "License").             **
 **  You may not use this file except in compliance with the License.         **
 **                                                                           **
 **  You can obtain a copy of the license at $PROJECT_ROOT/LICENSE            **
 **  or http://www.opensolaris.org/os/licensing.  This code is Open Source    **
 **  and you are free to use it within the confines of the license, even      **
 **  for your own closed-source commercial projects, as long as you follow    **
 **  the terms set forth in the CDDL.                                         **
 **                                                                           **
 **  When distributing Covered Code, include this CDDL HEADER in each         **
 **  file and include the License file at $PROJECT_ROOT/LICENSE.              **
 **  If applicable, add the following below this CDDL HEADER, with the        **
 **  fields enclosed by brackets "[]" replaced with your own identifying      **
 **  information: Portions Copyright [yyyy] [name of copyright owner]         **
 **                                                                           **
 ******************************************************************************/
// Modified $Date: 2010-03-16 20:45:00 -0600 (Tue, 16 Mar 2010) $ by $Author: bjames $
#define db_h_ID    "$Id: db.h 130 2010-03-17 02:45:00Z bjames $"

#include <iostream>
#include <fstream>
#include <map>
#include <vector>

#if defined(__MYSQLPP__)
#include <mysql++.h>
#define MYSQLPP_SSQLS_NO_STATICS
#endif

#include "../lib/common.h"

#define DEFAULT_SERVER_CONF "bdd.conf"
#define HELP_SETTING    1

//sql_create_14(MySQLArea, 1, 0,
//             mysqlpp::sql_int, idareas,
//             mysqlpp::sql_int, setting,
//             mysqlpp::sql_varchar, name,
//             mysqlpp::sql_text, desc,
//             mysqlpp::sql_int, north,
//             mysqlpp::sql_int, south,
//             mysqlpp::sql_int, west,
//             mysqlpp::sql_int, east,
//             mysqlpp::sql_int, contains,
//             mysqlpp::sql_int, npcs,
//             mysqlpp::sql_varchar, map,
//             mysqlpp::sql_int, up,
//             mysqlpp::sql_int, down,
//             mysqlpp::sql_varchar, title
//);
//



//! The base DataBase functionality
class DataBase
{
public:
    //constructor and destructor
    DataBase(std::string);
    virtual ~DataBase(void);

    virtual bool        Init() = 0;
    std::string DB() const { return db; }
    void        SetDB(std::string d) { db = d; }

protected:
    std::string db;
    bool        bInitialized;
    
};

#if defined (__MYSQLPP__)
class MySQLDB : public DataBase
{
public:
    MySQLDB(std::string);

    bool        Init();
    mysqlpp::StoreQueryResult  Query(const char *);

    std::vector<MySQLArea>         LoadAreas(int);
    int         LoadNPCs();

    std::string Host() const { return host; }
    std::string User() const { return dbuser; }
    std::string Pass() const { return dbpass; }
    void        SetHost(const std::string h) { host = h; }
    void        SetUser(const std::string u) { dbuser = u; }
    void        SetPass(const std::string p) { dbpass = p; }

private:
    std::string host;
    std::string dbuser;
    std::string dbpass;
    mysqlpp::Connection conn;

    static const char *     qSettings;
    static const char *     qAreas;
    static const char *     qNPCs;

};
#endif


class ServerCfg : public DataBase
{
public:
    ServerCfg(std::string f = DEFAULT_SERVER_CONF);

    bool        Init();
    int         Parse();

    std::string GetValue(std::string a) { return avpairs[a]; }
    void        AddAVPair(std::string a, std::string v) { avpairs[a] = v; }
    
private:
    std::map<std::string,std::string>    avpairs;
    std::ifstream    conf;

};

class DCONDB : public DataBase
{
public:

private:

};



#endif	/* _GS_DB_H_ */
